﻿#include "Launcher.AMain.h"
#include "../Settings.h"
#include "../../Shared/Language.h"
#include "../../Shared/Globals.h"
#include "../Program.h"
#include "Client.CMain.h"
#include "../Properties/Resources.Designer.h"

using namespace Client;

namespace Launcher
{

    AMain::AMain()
    {
        InitializeComponent();
        BackColor = Color::FromArgb(1, 0, 0);
        TransparencyKey = Color::FromArgb(1, 0, 0);
    }

    void AMain::SaveError(const std::string &ex)
    {
        try
        {
            if (Settings::RemainingErrorLogs-- > 0)
            {
                File::AppendAllText(R"(.\Error.txt)", StringHelper::formatSimple("[{0}] {1}{2}", DateTime::Now, ex, "\r\n"));
            }
        }
        catch (...)
        {
        }
    }

    void AMain::Start()
    {
        try
        {
            OldList = std::vector<FileInformation*>();
            DownloadList = std::deque<FileInformation*>();

            std::vector<unsigned char> data = Download(Settings::P_PatchFileName);

            if (!data.empty())
            {
//C# TO C++ CONVERTER NOTE: The following 'using' block is replaced by its C++ equivalent:
//ORIGINAL LINE: using (MemoryStream stream = new MemoryStream(data))
                {
                    MemoryStream stream = MemoryStream(data);
//C# TO C++ CONVERTER NOTE: The following 'using' block is replaced by its C++ equivalent:
//ORIGINAL LINE: using (BinaryReader reader = new BinaryReader(stream))
                    {
                    BinaryReader reader = BinaryReader(stream);
                    ParseOld(reader);
                    }
                }
            }
            else
            {
                MessageBox::Show(GameLanguage::PatchErr);
                Completed = true;
                return;
            }

            _fileCount = OldList.size();
            for (int i = 0; i < OldList.size(); i++)
            {
                CheckFile(OldList[i]);
            }

            Checked = true;
            _fileCount = 0;
            _currentCount = 0;


            _fileCount = DownloadList.size();
            BeginDownload();
        }
        catch (const EndOfStreamException &ex)
        {
            MessageBox::Show("End of stream found. Host is likely using a pre version 1.1.0.0 patch system");
            Completed = true;
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
            SaveError(ex->ToString());
        }
        catch (const std::runtime_error &ex)
        {
            MessageBox::Show(ex.what(), "Error");
            Completed = true;
            SaveError(ex.what());
        }
    }

    void AMain::BeginDownload()
    {
        if (DownloadList.empty())
        {
            return;
        }

        if (DownloadList.empty())
        {
            DownloadList = std::deque<FileInformation*>();
            _currentFile = nullptr;
            Completed = true;

            CleanUp();
            return;
        }

        _currentFile = DownloadList.pop_front();

        Download(_currentFile);
    }

    void AMain::CleanUp()
    {
        if (!CleanFiles)
        {
            return;
        }

        std::vector<std::string> fileNames = Directory::GetFiles(R"(.\)", "*.*", SearchOption::AllDirectories);
        std::string fileName;
        for (int i = 0; i < fileNames.size(); i++)
        {
            if (StringHelper::startsWith(fileNames[i], ".\\Screenshots\\"))
            {
                continue;
            }

            fileName = FileSystem::getFileName(fileNames[i]);

            if (fileName == "Mir2Config.ini" || fileName == System::AppDomain::CurrentDomain->FriendlyName)
            {
                continue;
            }

            try
            {
                if (!NeedFile(fileNames[i]))
                {
                    File::Delete(fileNames[i]);
                }
            }
            catch (...)
            {
            }
        }
    }

    bool AMain::NeedFile(const std::string &fileName)
    {
        for (int i = 0; i < OldList.size(); i++)
        {
            if (StringHelper::endsWith(fileName, OldList[i]->FileName))
            {
                return true;
            }
        }

        return false;
    }

    void AMain::ParseOld(BinaryReader *reader)
    {
        int count = reader->ReadInt32();

        for (int i = 0; i < count; i++)
        {
            FileInformation tempVar(reader);
            OldList.push_back(&tempVar);
        }
    }

    void AMain::CheckFile(FileInformation *old)
    {
        FileInformation *info = GetFileInformation(Settings::P_Client + old->FileName);
        _currentCount++;

        if (info == nullptr || old->Length != info->Length || old->Creation != info->Creation)
        {
            if (info != nullptr && (StringHelper::toLower(Path::GetExtension(old->FileName)) == ".dll" || StringHelper::toLower(Path::GetExtension(old->FileName)) == ".exe"))
            {
                std::string oldFilename = FileSystem::combine(FileSystem::getDirectoryName(old->FileName), ("Old__" + FileSystem::getFileName(old->FileName)));

                try
                {
                    FileSystem::renamePath(Settings::P_Client + old->FileName, oldFilename);
                }
                catch (const UnauthorizedAccessException &ex)
                {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
                    SaveError(ex->ToString());
                }
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to the exception 'finally' clause:
                finally
                {
                    //Might cause an infinite loop if it can never gain access
                    Restart = true;
                }
            }

            DownloadList.push_back(old);
            _totalBytes += old->Length;
        }
    }

    void AMain::Download(FileInformation *info)
    {
        std::string fileName = StringHelper::replace(info->FileName, R"(\)", "/");

        if (fileName != "PList.gz" && (info->Compressed != info->Length || info->Compressed == 0))
        {
            fileName += ".gz";
        }

        try
        {
//C# TO C++ CONVERTER NOTE: The following 'using' block is replaced by its C++ equivalent:
//ORIGINAL LINE: using (WebClient client = new WebClient())
            {
                WebClient client = WebClient();
                client.DownloadProgressChanged += [&] (o, e)
                {
                        _currentBytes = e::BytesReceived;
                };
                client.DownloadDataCompleted += [&] (o, e)
                {
                        if (e::Error != nullptr)
                        {
                            File::AppendAllText(R"(.\Error.txt)", StringHelper::formatSimple("[{0}] {1}{2}", DateTime::Now, info->FileName + " could not be downloaded. (" + e::Error->Message + ")", "\r\n"));
                            ErrorFound = true;
                        }
                        else
                        {
                            _currentCount++;
                            _completedBytes += _currentBytes;
                            _currentBytes = 0;
                            _stopwatch->Stop();
    
                            std::vector<unsigned char> raw = e::Result;
    
                            if (info->Compressed > 0 && info->Compressed != info->Length)
                            {
                                raw = Decompress(e::Result);
                            }
    
                            if (!FileSystem::directoryExists(Settings::P_Client + FileSystem::getDirectoryName(info->FileName)))
                            {
                                FileSystem::createDirectory(Settings::P_Client + FileSystem::getDirectoryName(info->FileName));
                            }
    
                            File::WriteAllBytes(Settings::P_Client + info->FileName, raw);
                            File::SetLastWriteTime(Settings::P_Client + info->FileName, info->Creation);
                        }
                        BeginDownload();
                };

                if (Settings::P_NeedLogin)
                {
                    client.Credentials = new NetworkCredential(Settings::P_Login, Settings::P_Password);
                }


                _stopwatch = Stopwatch::StartNew();
                Uri tempVar(Settings::P_Host + fileName);
                client.DownloadDataAsync(&tempVar);
            }
        }
        catch (...)
        {
            MessageBox::Show(StringHelper::formatSimple("Failed to download file: {0}", fileName));
        }
    }

    std::vector<unsigned char> AMain::Download(const std::string &fileName)
    {
        fileName = StringHelper::replace(fileName, R"(\)", "/");

        if (fileName != "PList.gz")
        {
            fileName += Path::GetExtension(fileName);
        }

        try
        {
//C# TO C++ CONVERTER NOTE: The following 'using' block is replaced by its C++ equivalent:
//ORIGINAL LINE: using (WebClient client = new WebClient())
            {
                WebClient client = WebClient();
                if (Settings::P_NeedLogin)
                {
                    client.Credentials = new NetworkCredential(Settings::P_Login, Settings::P_Password);
                }
                else
                {
                    client.Credentials = new NetworkCredential("", "");
                }

                return client.DownloadData(Settings::P_Host + Path::ChangeExtension(fileName, ".gz"));
            }
        }
        catch (...)
        {
            return std::vector<unsigned char>();
        }
    }

    std::vector<unsigned char> AMain::Decompress(std::vector<unsigned char> &raw)
    {
//C# TO C++ CONVERTER NOTE: The following 'using' block is replaced by its C++ equivalent:
//ORIGINAL LINE: using (GZipStream gStream = new GZipStream(new MemoryStream(raw), CompressionMode.Decompress))
        {
            MemoryStream tempVar(raw);
            GZipStream gStream = GZipStream(&tempVar, CompressionMode::Decompress);
            constexpr int size = 4096; //4kb
            std::vector<unsigned char> buffer(size);
//C# TO C++ CONVERTER NOTE: The following 'using' block is replaced by its C++ equivalent:
//ORIGINAL LINE: using (MemoryStream mStream = new MemoryStream())
            {
                MemoryStream mStream = MemoryStream();
                int count;
                do
                {
                    count = gStream.Read(buffer, 0, size);
                    if (count > 0)
                    {
                        mStream.Write(buffer, 0, count);
                    }
                } while (count > 0);
                return mStream.ToArray();
            }
        }
    }

    std::vector<unsigned char> AMain::Compress(std::vector<unsigned char> &raw)
    {
//C# TO C++ CONVERTER NOTE: The following 'using' block is replaced by its C++ equivalent:
//ORIGINAL LINE: using (MemoryStream mStream = new MemoryStream())
        {
            MemoryStream mStream = MemoryStream();
//C# TO C++ CONVERTER NOTE: The following 'using' block is replaced by its C++ equivalent:
//ORIGINAL LINE: using (GZipStream gStream = new GZipStream(mStream, CompressionMode.Compress, true))
            {
                GZipStream gStream = GZipStream(mStream, CompressionMode::Compress, true);
                gStream.Write(raw, 0, raw.size());
            }
            return mStream.ToArray();
        }
    }

    FileInformation *AMain::GetFileInformation(const std::string &fileName)
    {
        if (!FileSystem::fileExists(fileName))
        {
            return nullptr;
        }

        FileInfo *info = new FileInfo(fileName);

        delete info;
        FileInformation *tempVar = new FileInformation();
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to the .NET String 'Remove' method unless assigning to the string instance:
        tempVar->FileName = fileName.Remove(0, Settings::P_Client.length());
        tempVar->Length = static_cast<int>(info->Length);
        tempVar->Creation = info->LastWriteTime;

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar' statement was not added since tempVar was used in a 'return' or 'throw' statement.
        return tempVar;
    }

    void AMain::AMain_Load(std::any sender, EventArgs *e)
    {
        if (Settings::P_BrowserAddress != "")
        {
            Uri tempVar(Settings::P_BrowserAddress);
            Main_browser->Navigate(&tempVar);
        }

        RepairOldFiles();

        Launch_pb->Enabled = false;
        ProgressCurrent_pb->Width = 5;
        TotalProg_pb->Width = 5;
        Version_label->Text = StringHelper::formatSimple("Build: {0}.{1}.{2}", Globals::ProductCodename, Globals::ProductVersion, Application::ProductVersion);

        if (Settings::P_ServerName != "")
        {
            Name_label->Visible = true;
            Name_label->Text = Settings::P_ServerName;
        }

        _workThread = new Thread([&] () {Start();});
        _workThread->IsBackground = true;
        _workThread->Start();
    }

    void AMain::Launch_pb_Click(std::any sender, EventArgs *e)
    {
        Launch();
    }

    void AMain::Launch()
    {
        if (ConfigForm->Visible)
        {
            ConfigForm->Visible = false;
        }
        Program::Form = new CMain();
        Program::Form->Closed += [&] (s, args)
        {
            this->Close();
        };
        Program::Form->Show();
        Program::PForm->Hide();
    }

    void AMain::Close_pb_Click(std::any sender, EventArgs *e)
    {
        if (ConfigForm->Visible)
        {
            ConfigForm->Visible = false;
        }
        Close();
    }

    void AMain::Movement_panel_MouseClick(std::any sender, MouseEventArgs *e)
    {
        if (ConfigForm->Visible)
        {
            ConfigForm->Visible = false;
        }
        dragging = true;
        dragCursorPoint = Cursor::Position;
        dragFormPoint = this->Location;
    }

    void AMain::Movement_panel_MouseUp(std::any sender, MouseEventArgs *e)
    {
        dragging = false;
    }

    void AMain::Movement_panel_MouseMove(std::any sender, MouseEventArgs *e)
    {
        if (dragging)
        {
            Size tempVar(dragCursorPoint);
            Point *dif = Point::Subtract(Cursor::Position, &tempVar);
            Size tempVar2(dif);
            this->Location = Point->Add(dragFormPoint, &tempVar2);
        }
    }

    void AMain::Launch_pb_MouseEnter(std::any sender, EventArgs *e)
    {
        Launch_pb->Image = Client::Properties::Resources::getLaunchHover();
    }

    void AMain::Launch_pb_MouseLeave(std::any sender, EventArgs *e)
    {
        Launch_pb->Image = Client::Properties::Resources::getLaunchBase1();
    }

    void AMain::Close_pb_MouseEnter(std::any sender, EventArgs *e)
    {
        Close_pb->Image = Client::Properties::Resources::getCrossHover();
    }

    void AMain::Close_pb_MouseLeave(std::any sender, EventArgs *e)
    {
        Close_pb->Image = Client::Properties::Resources::getCrossBase();
    }

    void AMain::Launch_pb_MouseDown(std::any sender, MouseEventArgs *e)
    {
        Launch_pb->Image = Client::Properties::Resources::getLaunchPressed();
    }

    void AMain::Launch_pb_MouseUp(std::any sender, MouseEventArgs *e)
    {
        Launch_pb->Image = Client::Properties::Resources::getLaunchBase1();
    }

    void AMain::Close_pb_MouseDown(std::any sender, MouseEventArgs *e)
    {
        Close_pb->Image = Client::Properties::Resources::getCrossPressed();
    }

    void AMain::Close_pb_MouseUp(std::any sender, MouseEventArgs *e)
    {
        Close_pb->Image = Client::Properties::Resources::getCrossBase();
    }

    void AMain::ProgressCurrent_pb_SizeChanged(std::any sender, EventArgs *e)
    {
        ProgEnd_pb->Location = new Point((ProgressCurrent_pb->Location->X + ProgressCurrent_pb->Width), 490);
        if (ProgressCurrent_pb->Width == 0)
        {
            ProgEnd_pb->Visible = false;
        }
        else
        {
            ProgEnd_pb->Visible = true;
        }
    }

    void AMain::Config_pb_MouseDown(std::any sender, MouseEventArgs *e)
    {
        Config_pb->Image = Client::Properties::Resources::getConfigPressed();
    }

    void AMain::Config_pb_MouseEnter(std::any sender, EventArgs *e)
    {
        Config_pb->Image = Client::Properties::Resources::getConfigHover();
    }

    void AMain::Config_pb_MouseLeave(std::any sender, EventArgs *e)
    {
        Config_pb->Image = Client::Properties::Resources::getConfigBase();
    }

    void AMain::Config_pb_MouseUp(std::any sender, MouseEventArgs *e)
    {
        Config_pb->Image = Client::Properties::Resources::getConfigBase();
    }

    void AMain::Config_pb_Click(std::any sender, EventArgs *e)
    {
        if (ConfigForm->Visible)
        {
            ConfigForm->Hide();
        }
        else
        {
            ConfigForm->Show(Program::PForm);
        }
        ConfigForm->Location = new Point(Location->X + Config_pb->Location->X - 183, Location->Y + 36);
    }

    void AMain::TotalProg_pb_SizeChanged(std::any sender, EventArgs *e)
    {
        ProgTotalEnd_pb->Location = new Point((TotalProg_pb->Location->X + TotalProg_pb->Width), 508);
        if (TotalProg_pb->Width == 0)
        {
            ProgTotalEnd_pb->Visible = false;
        }
        else
        {
            ProgTotalEnd_pb->Visible = true;
        }
    }

    void AMain::Main_browser_DocumentCompleted(std::any sender, WebBrowserDocumentCompletedEventArgs *e)
    {
        if (Main_browser->Url->AbsolutePath != "blank")
        {
            Main_browser->Visible = true;
        }
    }

    void AMain::InterfaceTimer_Tick(std::any sender, EventArgs *e)
    {
        try
        {
            if (Completed)
            {

                ActionLabel->Text = "";
                CurrentFile_label->Text = "Up to date.";
                SpeedLabel->Text = "";
                ProgressCurrent_pb->Width = 550;
                TotalProg_pb->Width = 550;
                CurrentFile_label->Visible = true;
                CurrentPercent_label->Visible = true;
                TotalPercent_label->Visible = true;
                CurrentPercent_label->Text = "100%";
                TotalPercent_label->Text = "100%";
                InterfaceTimer->Enabled = false;
                Launch_pb->Enabled = true;
                if (ErrorFound)
                {
                    MessageBox::Show("One or more files failed to download, check Error.txt for details.", "Failed to Download.");
                }
                ErrorFound = false;

                if (CleanFiles)
                {
                    CleanFiles = false;
                    MessageBox::Show("Your files have been cleaned up.", "Clean Files");
                }

                if (Restart)
                {
                    Program::Restart = true;

                    MoveOldFilesToCurrent();

                    Close();
                }

                if (Settings::P_AutoStart)
                {
                    Launch();
                }
                return;
            }

            ActionLabel->Visible = true;
            SpeedLabel->Visible = true;
            CurrentFile_label->Visible = true;
            CurrentPercent_label->Visible = true;
            TotalPercent_label->Visible = true;

            if (LabelSwitch)
            {
                ActionLabel->Text = StringHelper::formatSimple("{0} Files Remaining", _fileCount - _currentCount);
            }
            else
            {
                ActionLabel->Text = std::string::Format("{0:#,##0}MB Remaining", ((_totalBytes) - (_completedBytes + _currentBytes)) / 1024 / 1024);
            }

            //ActionLabel.Text = string.Format("{0:#,##0}MB / {1:#,##0}MB", (_completedBytes + _currentBytes) / 1024 / 1024, _totalBytes / 1024 / 1024);

            if (_currentFile != nullptr)
            {
                //FileLabel.Text = string.Format("{0}, ({1:#,##0} MB) / ({2:#,##0} MB)", _currentFile.FileName, _currentBytes / 1024 / 1024, _currentFile.Compressed / 1024 / 1024);
                CurrentFile_label->Text = StringHelper::formatSimple("{0}", _currentFile->FileName);
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
                SpeedLabel->Text = (_currentBytes / 1024.0F / _stopwatch->Elapsed.TotalSeconds).ToString("#,##0.##") + "KB/s";
                CurrentPercent_label->Text = std::to_string(static_cast<int>(100 * _currentBytes / _currentFile->Length)) + "%";
                ProgressCurrent_pb->Width = static_cast<int>(5.5 * (100 * _currentBytes / _currentFile->Length));
            }
            TotalPercent_label->Text = std::to_string(static_cast<int>(100 * (_completedBytes + _currentBytes) / _totalBytes)) + "%";
            TotalProg_pb->Width = static_cast<int>(5.5 * (100 * (_completedBytes + _currentBytes) / _totalBytes));
        }
        catch (const std::runtime_error &ex)
        {

        }

    }

    void AMain::AMain_Click(std::any sender, EventArgs *e)
    {
        if (ConfigForm->Visible)
        {
            ConfigForm->Visible = false;
        }
    }

    void AMain::ActionLabel_Click(std::any sender, EventArgs *e)
    {
        LabelSwitch = !LabelSwitch;
    }

    void AMain::Credit_label_Click(std::any sender, EventArgs *e)
    {
        if (Credit_label->Text == "Powered by Crystal M2")
        {
            Credit_label->Text = "Designed by Breezer";
        }
        else
        {
            Credit_label->Text = "Powered by Crystal M2";
        }
    }

    void AMain::AMain_FormClosed(std::any sender, FormClosedEventArgs *e)
    {
        MoveOldFilesToCurrent();
    }

    void AMain::RepairOldFiles()
    {
        auto files = Directory::GetFiles(Settings::P_Client, "*", SearchOption::AllDirectories).Where([&] (std::any x)
        {
            return FileSystem::getFileName(x)->StartsWith("Old__");
        });

        for (auto oldFilename : *files)
        {
            if (!FileSystem::fileExists(oldFilename->Replace("Old__", "")))
            {
                FileSystem::renamePath(oldFilename, oldFilename->Replace("Old__", ""));
            }
            else
            {
                File::Delete(oldFilename);
            }
        }
    }

    void AMain::MoveOldFilesToCurrent()
    {
        auto files = Directory::GetFiles(Settings::P_Client, "*", SearchOption::AllDirectories).Where([&] (std::any x)
        {
            return FileSystem::getFileName(x)->StartsWith("Old__");
        });

        for (auto oldFilename : *files)
        {
            std::string originalFilename = FileSystem::combine(FileSystem::getDirectoryName(oldFilename), (FileSystem::getFileName(oldFilename)->Replace("Old__", "")));

            if (!FileSystem::fileExists(originalFilename) && FileSystem::fileExists(oldFilename))
            {
                FileSystem::renamePath(oldFilename, originalFilename);
            }
        }
    }

    void AMain::Dispose(bool disposing)
    {
        if (disposing && (components != nullptr))
        {
            components->Dispose();
        }
        System::Windows::Forms::Form::Dispose(disposing);
    }

    void AMain::InitializeComponent()
    {
        this->components = new System::ComponentModel::Container();
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to the C# 'typeof' operator:
        System::ComponentModel::ComponentResourceManager *resources = new System::ComponentModel::ComponentResourceManager(typeof(AMain));
        this->ActionLabel = new System::Windows::Forms::Label();
        this->SpeedLabel = new System::Windows::Forms::Label();
        this->InterfaceTimer = new System::Windows::Forms::Timer(this->components);
        this->Movement_panel = new System::Windows::Forms::Panel();
        this->Name_label = new System::Windows::Forms::Label();
        this->pictureBox1 = new System::Windows::Forms::PictureBox();
        this->Config_pb = new System::Windows::Forms::PictureBox();
        this->Close_pb = new System::Windows::Forms::PictureBox();
        this->Version_label = new System::Windows::Forms::Label();
        this->Main_browser = new System::Windows::Forms::WebBrowser();
        this->CurrentFile_label = new System::Windows::Forms::Label();
        this->CurrentPercent_label = new System::Windows::Forms::Label();
        this->TotalPercent_label = new System::Windows::Forms::Label();
        this->Credit_label = new System::Windows::Forms::Label();
        this->ProgTotalEnd_pb = new System::Windows::Forms::PictureBox();
        this->ProgEnd_pb = new System::Windows::Forms::PictureBox();
        this->ProgressCurrent_pb = new System::Windows::Forms::PictureBox();
        this->TotalProg_pb = new System::Windows::Forms::PictureBox();
        this->Launch_pb = new System::Windows::Forms::PictureBox();
        this->Movement_panel->SuspendLayout();
        (static_cast<System::ComponentModel::ISupportInitialize*>(this->pictureBox1))->BeginInit();
        (static_cast<System::ComponentModel::ISupportInitialize*>(this->Config_pb))->BeginInit();
        (static_cast<System::ComponentModel::ISupportInitialize*>(this->Close_pb))->BeginInit();
        (static_cast<System::ComponentModel::ISupportInitialize*>(this->ProgTotalEnd_pb))->BeginInit();
        (static_cast<System::ComponentModel::ISupportInitialize*>(this->ProgEnd_pb))->BeginInit();
        (static_cast<System::ComponentModel::ISupportInitialize*>(this->ProgressCurrent_pb))->BeginInit();
        (static_cast<System::ComponentModel::ISupportInitialize*>(this->TotalProg_pb))->BeginInit();
        (static_cast<System::ComponentModel::ISupportInitialize*>(this->Launch_pb))->BeginInit();
        this->SuspendLayout();
        // 
        // ActionLabel
        // 
        this->ActionLabel->Anchor = System::Windows::Forms::AnchorStyles::Bottom;
        this->ActionLabel->BackColor = System::Drawing::Color::Transparent;
        this->ActionLabel->Font = new System::Drawing::Font("Calibri", 8.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, (static_cast<unsigned char>(0)));
        this->ActionLabel->ForeColor = System::Drawing::Color::Gray;
        this->ActionLabel->Location = new System::Drawing::Point(504, 465);
        this->ActionLabel->Name = "ActionLabel";
        this->ActionLabel->Size = new System::Drawing::Size(108, 18);
        this->ActionLabel->TabIndex = 4;
        this->ActionLabel->Text = "1423MB/2000MB";
        this->ActionLabel->TextAlign = System::Drawing::ContentAlignment::MiddleRight;
        this->ActionLabel->Visible = false;
        this->ActionLabel->Click += new System::EventHandler(this->ActionLabel_Click);
        // 
        // SpeedLabel
        // 
        this->SpeedLabel->Anchor = System::Windows::Forms::AnchorStyles::Bottom;
        this->SpeedLabel->BackColor = System::Drawing::Color::Transparent;
        this->SpeedLabel->Font = new System::Drawing::Font("Calibri", 8.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, (static_cast<unsigned char>(0)));
        this->SpeedLabel->ForeColor = System::Drawing::Color::Gray;
        this->SpeedLabel->Location = new System::Drawing::Point(350, 469);
        this->SpeedLabel->Name = "SpeedLabel";
        this->SpeedLabel->RightToLeft = System::Windows::Forms::RightToLeft::No;
        this->SpeedLabel->Size = new System::Drawing::Size(71, 16);
        this->SpeedLabel->TabIndex = 13;
        this->SpeedLabel->Text = "Speed";
        this->SpeedLabel->TextAlign = System::Drawing::ContentAlignment::TopRight;
        this->SpeedLabel->Visible = false;
        // 
        // InterfaceTimer
        // 
        this->InterfaceTimer->Enabled = true;
        this->InterfaceTimer->Interval = 50;
        this->InterfaceTimer->Tick += new System::EventHandler(this->InterfaceTimer_Tick);
        // 
        // Movement_panel
        // 
        this->Movement_panel->BackColor = System::Drawing::Color::Transparent;
        this->Movement_panel->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Center;
        this->Movement_panel->Controls->Add(this->Name_label);
        this->Movement_panel->Controls->Add(this->pictureBox1);
        this->Movement_panel->Controls->Add(this->Config_pb);
        this->Movement_panel->Controls->Add(this->Close_pb);
        this->Movement_panel->Location = new System::Drawing::Point(5, 7);
        this->Movement_panel->Name = "Movement_panel";
        this->Movement_panel->Size = new System::Drawing::Size(790, 37);
        this->Movement_panel->TabIndex = 21;
        this->Movement_panel->MouseClick += new System::Windows::Forms::MouseEventHandler(this->Movement_panel_MouseClick);
        this->Movement_panel->MouseDown += new System::Windows::Forms::MouseEventHandler(this->Movement_panel_MouseClick);
        this->Movement_panel->MouseMove += new System::Windows::Forms::MouseEventHandler(this->Movement_panel_MouseMove);
        this->Movement_panel->MouseUp += new System::Windows::Forms::MouseEventHandler(this->Movement_panel_MouseUp);
        // 
        // Name_label
        // 
        this->Name_label->BackColor = System::Drawing::Color::Transparent;
        this->Name_label->Font = new System::Drawing::Font("Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, (static_cast<unsigned char>(0)));
        this->Name_label->ForeColor = System::Drawing::Color::White;
        this->Name_label->Image = ::Client->Properties->Resources::getServerBase();
        this->Name_label->Location = new System::Drawing::Point(307, 8);
        this->Name_label->Name = "Name_label";
        this->Name_label->Size = new System::Drawing::Size(186, 22);
        this->Name_label->TabIndex = 0;
        this->Name_label->Text = "Crystal Mir 2";
        this->Name_label->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
        this->Name_label->Visible = false;
        // 
        // pictureBox1
        // 
        this->pictureBox1->Image = ::Client->Properties->Resources::getServerBase();
        this->pictureBox1->Location = new System::Drawing::Point(307, -40);
        this->pictureBox1->Name = "pictureBox1";
        this->pictureBox1->Size = new System::Drawing::Size(186, 20);
        this->pictureBox1->TabIndex = 33;
        this->pictureBox1->TabStop = false;
        // 
        // Config_pb
        // 
        this->Config_pb->BackColor = System::Drawing::Color::Transparent;
        this->Config_pb->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Center;
        this->Config_pb->Image = ::Client->Properties->Resources::getConfigBase();
        this->Config_pb->Location = new System::Drawing::Point(739, 7);
        this->Config_pb->Name = "Config_pb";
        this->Config_pb->Size = new System::Drawing::Size(19, 20);
        this->Config_pb->TabIndex = 32;
        this->Config_pb->TabStop = false;
        this->Config_pb->Click += new System::EventHandler(this->Config_pb_Click);
        this->Config_pb->MouseDown += new System::Windows::Forms::MouseEventHandler(this->Config_pb_MouseDown);
        this->Config_pb->MouseEnter += new System::EventHandler(this->Config_pb_MouseEnter);
        this->Config_pb->MouseLeave += new System::EventHandler(this->Config_pb_MouseLeave);
        this->Config_pb->MouseUp += new System::Windows::Forms::MouseEventHandler(this->Config_pb_MouseUp);
        // 
        // Close_pb
        // 
        this->Close_pb->BackColor = System::Drawing::Color::Transparent;
        this->Close_pb->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Center;
        this->Close_pb->Image = ::Client->Properties->Resources::getCrossBase();
        this->Close_pb->Location = new System::Drawing::Point(763, 7);
        this->Close_pb->Name = "Close_pb";
        this->Close_pb->Size = new System::Drawing::Size(19, 20);
        this->Close_pb->TabIndex = 20;
        this->Close_pb->TabStop = false;
        this->Close_pb->Click += new System::EventHandler(this->Close_pb_Click);
        this->Close_pb->MouseDown += new System::Windows::Forms::MouseEventHandler(this->Close_pb_MouseDown);
        this->Close_pb->MouseEnter += new System::EventHandler(this->Close_pb_MouseEnter);
        this->Close_pb->MouseLeave += new System::EventHandler(this->Close_pb_MouseLeave);
        this->Close_pb->MouseUp += new System::Windows::Forms::MouseEventHandler(this->Close_pb_MouseUp);
        // 
        // Version_label
        // 
        this->Version_label->Anchor = System::Windows::Forms::AnchorStyles::Bottom;
        this->Version_label->BackColor = System::Drawing::Color::Transparent;
        this->Version_label->Font = new System::Drawing::Font("Calibri", 8.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, (static_cast<unsigned char>(0)));
        this->Version_label->ForeColor = System::Drawing::Color::Gray;
        this->Version_label->Location = new System::Drawing::Point(582, 530);
        this->Version_label->Name = "Version_label";
        this->Version_label->Size = new System::Drawing::Size(210, 13);
        this->Version_label->TabIndex = 31;
        this->Version_label->Text = "Version 1.0.0.0";
        this->Version_label->TextAlign = System::Drawing::ContentAlignment::TopRight;
        // 
        // Main_browser
        //
        this->Main_browser->AllowWebBrowserDrop = false;
        this->Main_browser->IsWebBrowserContextMenuEnabled = false;
        this->Main_browser->Location = new System::Drawing::Point(8, 46);
        this->Main_browser->MinimumSize = new System::Drawing::Size(20, 20);
        this->Main_browser->Name = "Main_browser";
        this->Main_browser->ScriptErrorsSuppressed = true;
        this->Main_browser->ScrollBarsEnabled = false;
        this->Main_browser->Size = new System::Drawing::Size(784, 411);
        this->Main_browser->TabIndex = 24;
        this->Main_browser->Url = new System::Uri("", System::UriKind::Relative);
        this->Main_browser->Visible = false;
        this->Main_browser->WebBrowserShortcutsEnabled = false;
        this->Main_browser->DocumentCompleted += new System::Windows::Forms::WebBrowserDocumentCompletedEventHandler(this->Main_browser_DocumentCompleted);
        // 
        // CurrentFile_label
        // 
        this->CurrentFile_label->Anchor = System::Windows::Forms::AnchorStyles::Bottom;
        this->CurrentFile_label->BackColor = System::Drawing::Color::Transparent;
        this->CurrentFile_label->Font = new System::Drawing::Font("Calibri", 8.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, (static_cast<unsigned char>(0)));
        this->CurrentFile_label->ForeColor = System::Drawing::Color::Gray;
        this->CurrentFile_label->Location = new System::Drawing::Point(59, 467);
        this->CurrentFile_label->Name = "CurrentFile_label";
        this->CurrentFile_label->Size = new System::Drawing::Size(362, 17);
        this->CurrentFile_label->TabIndex = 27;
        this->CurrentFile_label->Text = "Checking Files.";
        this->CurrentFile_label->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
        this->CurrentFile_label->Visible = false;
        // 
        // CurrentPercent_label
        // 
        this->CurrentPercent_label->Anchor = System::Windows::Forms::AnchorStyles::Bottom;
        this->CurrentPercent_label->BackColor = System::Drawing::Color::Transparent;
        this->CurrentPercent_label->Font = new System::Drawing::Font("Calibri", 8.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, (static_cast<unsigned char>(0)));
        this->CurrentPercent_label->ForeColor = System::Drawing::Color::Gray;
        this->CurrentPercent_label->Location = new System::Drawing::Point(616, 489);
        this->CurrentPercent_label->Name = "CurrentPercent_label";
        this->CurrentPercent_label->Size = new System::Drawing::Size(35, 20);
        this->CurrentPercent_label->TabIndex = 28;
        this->CurrentPercent_label->Text = "100%";
        this->CurrentPercent_label->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
        this->CurrentPercent_label->Visible = false;
        // 
        // TotalPercent_label
        // 
        this->TotalPercent_label->Anchor = System::Windows::Forms::AnchorStyles::Bottom;
        this->TotalPercent_label->BackColor = System::Drawing::Color::Transparent;
        this->TotalPercent_label->Font = new System::Drawing::Font("Calibri", 8.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, (static_cast<unsigned char>(0)));
        this->TotalPercent_label->ForeColor = System::Drawing::Color::Gray;
        this->TotalPercent_label->Location = new System::Drawing::Point(616, 506);
        this->TotalPercent_label->Name = "TotalPercent_label";
        this->TotalPercent_label->Size = new System::Drawing::Size(35, 20);
        this->TotalPercent_label->TabIndex = 29;
        this->TotalPercent_label->Text = "100%";
        this->TotalPercent_label->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
        this->TotalPercent_label->Visible = false;
        // 
        // Credit_label
        // 
        this->Credit_label->Anchor = System::Windows::Forms::AnchorStyles::Bottom;
        this->Credit_label->AutoSize = true;
        this->Credit_label->BackColor = System::Drawing::Color::Transparent;
        this->Credit_label->Font = new System::Drawing::Font("Calibri", 8.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, (static_cast<unsigned char>(0)));
        this->Credit_label->ForeColor = System::Drawing::Color::Gray;
        this->Credit_label->Location = new System::Drawing::Point(12, 530);
        this->Credit_label->Name = "Credit_label";
        this->Credit_label->Size = new System::Drawing::Size(114, 13);
        this->Credit_label->TabIndex = 30;
        this->Credit_label->Text = "Powered by Crystal M2";
        this->Credit_label->Click += new System::EventHandler(this->Credit_label_Click);
        // 
        // ProgTotalEnd_pb
        // 
        this->ProgTotalEnd_pb->Anchor = System::Windows::Forms::AnchorStyles::None;
        this->ProgTotalEnd_pb->BackColor = System::Drawing::Color::Transparent;
        this->ProgTotalEnd_pb->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Center;
        this->ProgTotalEnd_pb->Image = ::Client->Properties->Resources::getNEWProgressEnd_Blue_();
        this->ProgTotalEnd_pb->Location = new System::Drawing::Point(608, 508);
        this->ProgTotalEnd_pb->Name = "ProgTotalEnd_pb";
        this->ProgTotalEnd_pb->Size = new System::Drawing::Size(4, 15);
        this->ProgTotalEnd_pb->TabIndex = 26;
        this->ProgTotalEnd_pb->TabStop = false;
        // 
        // ProgEnd_pb
        // 
        this->ProgEnd_pb->Anchor = System::Windows::Forms::AnchorStyles::None;
        this->ProgEnd_pb->BackColor = System::Drawing::Color::Transparent;
        this->ProgEnd_pb->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Center;
        this->ProgEnd_pb->Image = ::Client->Properties->Resources::getNEWProgressEnd_Green_();
        this->ProgEnd_pb->Location = new System::Drawing::Point(608, 490);
        this->ProgEnd_pb->Name = "ProgEnd_pb";
        this->ProgEnd_pb->Size = new System::Drawing::Size(4, 15);
        this->ProgEnd_pb->TabIndex = 25;
        this->ProgEnd_pb->TabStop = false;
        // 
        // ProgressCurrent_pb
        // 
        this->ProgressCurrent_pb->Anchor = System::Windows::Forms::AnchorStyles::None;
        this->ProgressCurrent_pb->BackColor = System::Drawing::Color::Transparent;
        this->ProgressCurrent_pb->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Center;
        this->ProgressCurrent_pb->Image = ::Client->Properties->Resources::getGreenProgress();
        this->ProgressCurrent_pb->Location = new System::Drawing::Point(58, 490);
        this->ProgressCurrent_pb->Name = "ProgressCurrent_pb";
        this->ProgressCurrent_pb->Size = new System::Drawing::Size(550, 15);
        this->ProgressCurrent_pb->TabIndex = 23;
        this->ProgressCurrent_pb->TabStop = false;
        this->ProgressCurrent_pb->SizeChanged += new System::EventHandler(this->ProgressCurrent_pb_SizeChanged);
        // 
        // TotalProg_pb
        // 
        this->TotalProg_pb->Anchor = System::Windows::Forms::AnchorStyles::None;
        this->TotalProg_pb->BackColor = System::Drawing::Color::Transparent;
        this->TotalProg_pb->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Center;
        this->TotalProg_pb->Image = ::Client->Properties->Resources::getBlueProgress();
        this->TotalProg_pb->Location = new System::Drawing::Point(58, 508);
        this->TotalProg_pb->Name = "TotalProg_pb";
        this->TotalProg_pb->Size = new System::Drawing::Size(550, 14);
        this->TotalProg_pb->TabIndex = 22;
        this->TotalProg_pb->TabStop = false;
        this->TotalProg_pb->SizeChanged += new System::EventHandler(this->TotalProg_pb_SizeChanged);
        // 
        // Launch_pb
        // 
        this->Launch_pb->Anchor = System::Windows::Forms::AnchorStyles::Bottom;
        this->Launch_pb->BackColor = System::Drawing::Color::Transparent;
        this->Launch_pb->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Stretch;
        this->Launch_pb->Cursor = System::Windows::Forms::Cursors::Hand;
        this->Launch_pb->Image = ::Client->Properties->Resources::getLaunchBase1();
        this->Launch_pb->Location = new System::Drawing::Point(658, 472);
        this->Launch_pb->Name = "Launch_pb";
        this->Launch_pb->Size = new System::Drawing::Size(116, 54);
        this->Launch_pb->TabIndex = 19;
        this->Launch_pb->TabStop = false;
        this->Launch_pb->Click += new System::EventHandler(this->Launch_pb_Click);
        this->Launch_pb->MouseDown += new System::Windows::Forms::MouseEventHandler(this->Launch_pb_MouseDown);
        this->Launch_pb->MouseEnter += new System::EventHandler(this->Launch_pb_MouseEnter);
        this->Launch_pb->MouseLeave += new System::EventHandler(this->Launch_pb_MouseLeave);
        this->Launch_pb->MouseUp += new System::Windows::Forms::MouseEventHandler(this->Launch_pb_MouseUp);
        // 
        // AMain
        // 
        this->AutoScaleDimensions = new System::Drawing::SizeF(6.0F, 13.0F);
        this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
        this->BackColor = System::Drawing::SystemColors::ActiveCaption;
        this->BackgroundImage = ::Client->Properties->Resources::getPfffft();
        this->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Center;
        this->ClientSize = new System::Drawing::Size(800, 548);
        this->Controls->Add(this->SpeedLabel);
        this->Controls->Add(this->Credit_label);
        this->Controls->Add(this->Version_label);
        this->Controls->Add(this->TotalPercent_label);
        this->Controls->Add(this->CurrentPercent_label);
        this->Controls->Add(this->CurrentFile_label);
        this->Controls->Add(this->ProgTotalEnd_pb);
        this->Controls->Add(this->ProgEnd_pb);
        this->Controls->Add(this->Main_browser);
        this->Controls->Add(this->ProgressCurrent_pb);
        this->Controls->Add(this->TotalProg_pb);
        this->Controls->Add(this->Launch_pb);
        this->Controls->Add(this->ActionLabel);
        this->Controls->Add(this->Movement_panel);
        this->DoubleBuffered = true;
        this->ForeColor = System::Drawing::SystemColors::ControlText;
        this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::None;
        this->Icon = (std::any_cast<System::Drawing::Icon*>(resources->GetObject("$this.Icon")));
        this->MaximizeBox = false;
        this->MinimizeBox = false;
        this->Name = "AMain";
        this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
        this->Text = "Launcher";
        this->TransparencyKey = System::Drawing::Color::Black;
        this->FormClosed += new System::Windows::Forms::FormClosedEventHandler(this->AMain_FormClosed);
        this->Load += new System::EventHandler(this->AMain_Load);
        this->Click += new System::EventHandler(this->AMain_Click);
        this->Movement_panel->ResumeLayout(false);
        (static_cast<System::ComponentModel::ISupportInitialize*>(this->pictureBox1))->EndInit();
        (static_cast<System::ComponentModel::ISupportInitialize*>(this->Config_pb))->EndInit();
        (static_cast<System::ComponentModel::ISupportInitialize*>(this->Close_pb))->EndInit();
        (static_cast<System::ComponentModel::ISupportInitialize*>(this->ProgTotalEnd_pb))->EndInit();
        (static_cast<System::ComponentModel::ISupportInitialize*>(this->ProgEnd_pb))->EndInit();
        (static_cast<System::ComponentModel::ISupportInitialize*>(this->ProgressCurrent_pb))->EndInit();
        (static_cast<System::ComponentModel::ISupportInitialize*>(this->TotalProg_pb))->EndInit();
        (static_cast<System::ComponentModel::ISupportInitialize*>(this->Launch_pb))->EndInit();
        this->ResumeLayout(false);
        this->PerformLayout();

        delete resources;
    }
}
